package com.tanhua.admin.service;

import com.tanhua.admin.mapper.LogMapper;
import com.tanhua.model.vo.SummaryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ManagementService{

    @Autowired
    private LogMapper logMapper;

    public SummaryVo summary() {

        //累计
        Integer a = logMapper.cumulativeUsers();
        //过去7天活跃用户
        Integer b = logMapper.activePassWeek();
        //过去30天活跃用户
        Integer c = logMapper.activePassMonth();
        //今日新增用户
        Integer d = logMapper.newUsersToday();
        //昨日新增用户
        Integer x = logMapper.newUsersYestoday();
        if(x == 0) {
            x = 10;
        }
        //今日新增用户涨跌率，单位百分数，正数为涨，负数为跌
        int e = (d - x) / x*100;
        //今日登录次数
        Integer f = logMapper.loginTimesToday();
        //昨日登录次数
        Integer y = logMapper.loginTimesYestoday();
        //今日登录次数涨跌率，单位百分数，正数为涨，负数为跌
        int g = (e - y) / y*100;
        //今日活跃用户
        Integer h = logMapper.activeUsersToday();
        //昨日活跃用户
        Integer z = logMapper.activeUsersYestoday();
        //今日活跃用户涨跌率，单位百分数，正数为涨，负数为跌
        int i = (f - z) / z*100;

        //构建vo返回
        SummaryVo vo = new SummaryVo();
        vo.setCumulativeUsers(a);
        vo.setActivePassWeek(b);
        vo.setActivePassMonth(c);
        vo.setNewUsersToday(d);
        vo.setNewUsersTodayRate(e);
        vo.setLoginTimesToday(f);
        vo.setLoginTimesTodayRate(g);
        vo.setActiveUsersToday(h);
        vo.setActiveUsersTodayRate(i);
        return vo;
    }
}
